package com.cskt.petproject178.service.impl;

import com.cskt.petproject178.mapper.CommentMapper;
import com.cskt.petproject178.mapper.CommentPicMapper;
import com.cskt.petproject178.pojo.param.CommodityListParam;
import com.cskt.petproject178.pojo.vo.CommentVO;
import com.cskt.petproject178.pojo.vo.PageVO;
import com.cskt.petproject178.service.CommentProductParamService;
import com.cskt.petproject178.service.third.AliyunOSSService;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 27013
 **/

@Service
public class CommentProductParamServiceImpl implements CommentProductParamService {

    @Resource
    private CommentMapper commentMapper;

    @Resource
    private AliyunOSSService aliyunOSSService;
    @Override
    public PageVO<CommentVO> selectCommentParam( Long spuId, Integer isPic, Integer currentPage, Integer pageSize) {
        List<CommentVO> commentVOList = commentMapper.selectCommentParam(spuId,isPic,currentPage,pageSize);
        Integer total=commentMapper.selectCommentParamCount(spuId,isPic);
        //获取图片路径
        commentVOList.forEach(commentVO -> {
            commentVO.setImgList(commentVO.getImgList().stream().map(img -> aliyunOSSService.getObjUrl(img)).collect(Collectors.toList()));
        });

        return PageVO.page(currentPage,pageSize, total, commentVOList);
    }
}
